﻿
@section scripts{
    <script type="text/javascript">
        var bootstrap = function ($, ibpm) {
            "use strict";
            var refreshPost;
            var page = {
                init: function () {
                    $("#En_add").on('click', page.AddAct);
                    $("#En_edit").on('click', page.EditAct);
                    $("#En_delete").on('click', page.DelAct);
                    $("#btn_Search").on('click', function () {
                        page.search();
                    });
                    $('#btn_Refresh').on('click', function () {
                        location.reload();
                    });
                    //开启文件选择
                    $('#uploadBtn').on('click', function () {
                        $('#upload').click();
                    });
                    //上传头像
                    $('#upload').on('change', function () {
                        var arr = $('#upload').val().split('\\');
                        if (arr.length > 0) {
                            var formData = new FormData($("#uploadForm")[0]);
                            $.ajax({
                                type: "POST",
                                data: formData,
                                dataType: "json",
                                url: top.$.rootUrl + "/WorkDone/UploadPicBit",
                                contentType: false,
                                processData: false,
                                success: function (data) {
                                    $('#upload').val('');
                                    if (data.status) {
                                        $("#picshow").attr("src", data.url);
                                        $('#HeadIcon').val(data.url);
                                    } else {
                                        alert(data.msg);
                                    }
                                },
                                error: function (data) {
                                    $('#upload').val('');
                                    alert(data);
                                }
                            });
                        }
                    });
                    page.initGrid();
                    page.bind();
                },
                bind: function () {
                    //公司信息
                    $('#using_tree').ibpm_tree({
                        url: top.$.rootUrl + '/Org/OrgUser/GetOrgTree',
                        icons: true,
                        hasSearch: true,
                        isLeaf: false,
                        multiple: false,
                        nodeClick: function (item) {
                            ibpm.httpAsyncPost(top.$.rootUrl + "/Org/OrgUser/GetDeptCom", { id: item }, function (json) {
                                $('#CurrCompanyID').val(json.data.ComId);
                                $('#CurrCompanyName').val(json.data.ComName);
                                $('#CurrDeptID').val(json.data.DeptId);
                                $('#CurrDeptName').val(json.data.DeptName);
                                page.search();
                            });
                        }
                    });

                    //配置岗位
                    $('#F_Post').bind("click", function () {
                        var ModifyUserId = $('#ModifyUserId').val();
                        if (ModifyUserId == undefined || ModifyUserId == '' || ModifyUserId == null)
                            return;

                        var UserId = $('#UserId').val();
                        UserId = escape(UserId);
                        ibpm.layerForm({
                            id: 'SelectPost',
                            title: '配置岗位',
                            url: top.$.rootUrl + '/Org/OrgUser/GetSelectLayer?UserId=' + UserId,
                            width: 460,
                            height: 640,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshPost);
                            }
                        });
                    });
                },
                initGrid: function () {
                    //绑定列表数据
                    $('#gridtable').jfGrid({
                        url: top.$.rootUrl + '/Org/OrgUser/GetPageList',
                        headData: [
                            { label: '用户', name: 'FullName', index: "FullName", width: 120, align: 'left' },
                            { label: '工号', name: 'JobNumber', width: 100, align: 'left' },
                            { label: '账户', name: 'Account', width: 120, align: 'left' },
                            { label: '应用', name: 'ApplyKey', width: 100, align: 'left' },
                            { label: '公司', name: 'CompanyName', width: 160, align: 'left' },
                            { label: '部门', name: 'DepartmentName', width: 100, align: 'left' }
                        ],
                        mainId: 'UserId',
                        sidx: 'JobNumber',    //排序
                        sord: 'desc',
                        isPage: true,
                        rows: 18,
                    });
                },
                AddAct: function () {
                    var companyId = $('#CurrCompanyID').val();
                    var deptId = $('#CurrDeptID').val();
                    if (ibpm.checkrow(deptId)) {
                        ibpm.httpAsyncPost(top.$.rootUrl + "/Org/OrgUser/NodeAdd", { companyId: companyId, deptId: deptId }, function (json) {
                            $("#NodeSave").ibpm_SetFormData(json.data);
                            $("#picshow").attr("src", json.data.HeadIcon);
                            setTimeout(function () {
                                $('#CompanyName').val($('#CurrCompanyName').val());
                                $('#DepartmentName').val($('#CurrDeptName').val());
                            }, 300);
                            $('#AddNode').modal("show");
                        });
                    }
                },
                EditAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('UserId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.postForm(top.$.rootUrl + "/Org/OrgUser/NodeEdit", { keyValue: keyValue }, function (json) {
                            $("#NodeSave").ibpm_SetFormData(json.data);
                            $("#picshow").attr("src", json.data.HeadIcon);
                            $('#AddNode').modal("show");
                        });
                    }
                },
                DelAct: function () {
                    var keyValue = $('#gridtable').jfGridValue('UserId');
                    if (ibpm.checkrow(keyValue)) {
                        ibpm.layerConfirm('是否确认删除该项！', function (res) {
                            if (res) {
                                ibpm.deleteForm(top.$.rootUrl + '/Org/OrgUser/NodeDelete', { keyValue: keyValue }, function () {
                                    page.search();
                                });
                            }
                        });
                    }
                },
                search: function (param) {
                    param = param || {};
                    param.companyId = $('#CurrCompanyID').val();
                    param.deptId = $('#CurrDeptID').val();
                    param.keyword = $('#txt_Keyword').val();
                    $('#gridtable').jfGridSet('reload', param);
                }
            };
            page.init();
            refreshPost = function (data) {
                //alert(data);
                var UID = $('#UserId').val();
                var param = { EnId: UID };
                param.ContentTxt = data;
                ibpm.httpAsyncPost(top.$.rootUrl + "/Org/OrgUser/SaveUserPost", param, function (json) {
                    if (!!json.info)
                        $('#PostTitle').val(json.info);
                });
            };
        };
        function EndReq(data) {
            $('#AddNode').modal("hide");
            $('#gridtable').jfGridSet('reload');
        };
    </script>
}

<div class="row">
    <div class="step-pane">
        <div class="row">
            <div class="col-md-5">
                <div class="input-group">
                    <input type="hidden" id="CurrCompanyID" value="" />
                    <input type="hidden" id="CurrCompanyName" value="" />
                    <input type="hidden" id="CurrDeptID" value="" />
                    <input type="hidden" id="CurrDeptName" value="" />
                    <input id="txt_Keyword" type="text" class="form-control-sm form-control" placeholder="请输入要查询的关键字" />
                    <span id="btn_Search" class="input-group-addon btn btn-primary"><i class="fa fa-search"></i>&nbsp;搜索</span>
                    <span id="btn_Refresh" class="input-group-addon btn btn-info"><i class="fa fa-refresh"></i>&nbsp;刷新</span>
                </div>
            </div>
            <div class="col-md-7">
                <div class="btn-group btn-group-sm" style="float:right;">
                    <a id="En_add" class="btn btn-default"><i class="fa fa-plus"></i>&nbsp;新增用户</a>
                    <a id="En_edit" class="btn btn-default"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑用户</a>
                    <a id="En_delete" class="btn btn-default"><i class="fa fa-trash-o"></i>&nbsp;删除用户</a>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="step-pane">
        <div class="row" style="margin: 5px;">
            <div class="col-lg-4">
                <div class="step-pane">
                    <h3 class="modal-title">组织架构</h3>
                    <div id="using_tree"></div>
                </div>
            </div>
            <div class="col-lg-8">
                <div id="gridtable"></div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="AddNode" tabindex="-11" role="dialog" aria-labelledby="AddNode" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content animated bounceInRight">
            <div class="modal-header">
                <h3 class="modal-title">用户信息</h3>
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                </button>
            </div>
            <form action="/Org/OrgUser/NodeSave" id="NodeSave" method="post" onsubmit="return FormSaveReport('NodeSave');">
                <div class="modal-body">
                    <input type="hidden" id="UserId" name="UserId" value="" />
                    <input type="hidden" id="CompanyId" name="CompanyId" value="" />
                    <input type="hidden" id="HeadIcon" name="HeadIcon" value="" />
                    <input type="hidden" id="ApplyKey" name="ApplyKey" value="" />
                    <input type="hidden" id="DepartmentId" name="DepartmentId" value="" />
                    <input type="hidden" id="ModifyUserId" name="ModifyUserId" value="" />
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>登录账户</label>
                            <input class="form-control single-line" id="Account" name="Account" placeholder="登录账户" type="text" value="">
                        </div>
                        <div class="form-group col-sm-6">
                            <label>工号</label>
                            <input class="form-control single-line" id="JobNumber" name="JobNumber" type="text" readonly>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>名称</label>
                            <input class="form-control single-line" id="FullName" name="FullName" placeholder="名称" type="text" value="">
                        </div>
                        <div class="form-group col-sm-6">
                            <label>配置岗位</label>
                            <div class="input-group date" id="F_Post">
                                <span class="input-group-addon"><i class="fa fa-address-card"></i></span>
                                <input class="form-control" id="PostTitle" name="PostTitle" readonly type="text" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group col-sm-6">
                            <label>真实姓名</label>
                            <input class="form-control single-line" id="RealName" name="RealName" placeholder="真实姓名" type="text" value="">
                            <label>呢称</label>
                            <input class="form-control single-line" id="NickName" name="NickName" placeholder="呢称" type="text" value="">
                            <label>公司</label>
                            <input class="form-control single-line" id="CompanyName" name="CompanyName" type="text" readonly value="">
                            <label>部门</label>
                            <input class="form-control single-line" id="DepartmentName" name="DepartmentName" type="text" readonly value="">
                        </div>
                        <div class="form-group col-sm-6">
                            <div style="padding: 10px;text-align: center;">
                                <img id="picshow" style="height: 200px; width: 200px;" src="" alt="...头像">
                                <button type="button" id="uploadBtn" class="btn btn-primary btn-xs">头像上传</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
                    <input type="submit" value="Save" class="btn btn-success">
                </div>
            </form>
            <form id="uploadForm" method="post" enctype="multipart/form-data" role="form">
                <input id="upload" name="upload" accept="image/gif, image/png, image/jpeg" type="file" style="display:none" />
            </form>
        </div>
    </div>
</div>
